package c_interface;

/**
 * 测试类，用于演示学生信息的排序
 *
 * @author Cheng-02
 * @version V1.0
 * @Package c_interface
 * @date 2024/4/1 下午1:30
 */
public class Test04 {
    public static void main(String[] args) {
        // 初始化学生数组
        Student[] student = new Student[3];
        // 创建并初始化学生对象
        Student s1 = new Student("张三", 100);
        Student s2 = new Student("李四", 80);
        Student s3 = new Student("王五", 60);
        student[0] = s1;
        student[1] = s2;
        student[2] = s3;

        // 使用冒泡排序对学生数组进行降序排序
        for (int j = 0; j < student.length - 1; j++) {
            for (int i = 0; i < student.length - 1 - j; i++) {
                // 如果前一个学生分数大于后一个学生分数，则交换位置
                if (student[i].compareTo(student[i + 1]) > 0) {
                    Student temp = student[i];
                    student[i] = student[i + 1];
                    student[i + 1] = temp;
                }
            }
        }

        // 打印排序后的学生信息
        for (int i = 0; i < student.length; i++) {
            System.out.println(student[i].getName() + " " + student[i].getScore());

        }
    }

}

